package com.zf.shuashua.utils;

import android.os.Looper;
import android.text.TextUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Collection;
import java.util.Map;


public class WebUtils {

	public static String concat(String...params){
		StringBuilder mStringBuilder=new StringBuilder();
		for(int i=0;i<params.length;i++){
			String param=params[i];
			if(!isJson(param)){
				mStringBuilder.append("\"").append(param).append("\"");
			}else{
				mStringBuilder.append(param);
			}
			if(i!=params.length-1){
				mStringBuilder.append(" , ");
			}
		}
		return mStringBuilder.toString();
	}

	static boolean isJson(String target) {
		if (TextUtils.isEmpty(target)) {
			return false;
		}
		boolean tag = false;
		try {
			if (target.startsWith("[")) {
				new JSONArray(target);
			} else {
				new JSONObject(target);
			}
			tag = true;
		} catch (JSONException ignore) {
//            ignore.printStackTrace();
			tag = false;
		}
		return tag;
	}

	public static boolean isUIThread() {
		return Looper.myLooper() == Looper.getMainLooper();
	}

	static boolean isEmptyCollection(Collection collection) {
		return collection == null || collection.isEmpty();
	}

	static boolean isEmptyMap(Map map) {
		return map == null || map.isEmpty();
	}

}
